<?php

class Access_Logger_Core
{
	public static function add()
	{
		$cookie_value = cookie::get('site_tracking', NULL);
		if ($cookie_value == NULL)
		{
			$cookie_value = text::random('alnum', 15);
			cookie::set(array('name' => 'site_tracking', 'value' => $cookie_value, 'expire' => 3600));
		}

		$log = new Access_Log_Model();
		$log->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
		$log->file = Router::$complete_uri == '' ? '/' : Router::$complete_uri;
		$log->date = time();
		$log->method = $_SERVER['REQUEST_METHOD'];
		$log->protocol = $_SERVER['SERVER_PROTOCOL'];
		$log->language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
		$log->user_agent = $_SERVER['HTTP_USER_AGENT'];
		$log->remote_addr = $_SERVER['REMOTE_ADDR'];
		$log->session_id = $cookie_value;

		$log->save();
	}
}